package com.sixth.service.impl;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.sixth.annotation.PageInfoAdvice;
import com.sixth.bean.MarketAddress;
import com.sixth.bean.MarketAddressExample;
import com.sixth.bean.MarketUserExample;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BasePageInfoVo;
import com.sixth.mapper.MarketAddressMapper;
import com.sixth.service.AdminAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

/**
 * @ClassName AdminAddressServiceImpl
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/7 15:57
 **/

@Service
public class AdminAddressServiceImpl implements AdminAddressService {

    @Autowired
    MarketAddressMapper marketAddressMapper;


    @PageInfoAdvice
    @Override
    public Object list(BasePageInfo basePageInfo, Integer userId, String name) {
        //new PageInfo<>()
        // 如果userId不为空，精确匹配
        MarketAddressExample example = new MarketAddressExample();

        MarketAddressExample.Criteria criteria = example.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }

        // 如果name不为空，模糊匹配
        if (!StringUtil.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }

        example.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());
        List<MarketAddress> marketAddresses = marketAddressMapper.selectByExample(example);
        return marketAddresses;
    }
}
